package com.pureut.storage.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.storage.dto.WarehouseDto;
import com.pureut.storage.service.WarehouseService;
import com.pureut.storage.vo.WarehouseVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 仓库控制层
 * Author:C
 * Date:2022/12/13 17:27
 * @DESC
 */
@RestController
@RequestMapping("/warehouse")
public class WarehouseController extends BaseController {


    @Resource
    WarehouseService warehouseService;

    /**
     * 获取仓库列表
     */
    @RequiresPermissions("warehouse:warmanage:modeling:list")
    @GetMapping("/list")
    public AjaxResult list(WarehouseVo warehouseVo) {
        return AjaxResult.success(warehouseService.getList(warehouseVo));
    }

    /**
     * 新增仓库
     */
    @RequiresPermissions("warehouse:warmanage:modeling:add")
    @Log(title = "新增仓库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody WarehouseVo warehouseVo) {
        return toAjax(warehouseService.addWarehouse(warehouseVo));
    }

    /**
     * 修改仓库
     */
    @RequiresPermissions("warehouse:warmanage:modeling:edit")
    @Log(title = "修改仓库", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody WarehouseVo warehouseVo) {
        return toAjax(warehouseService.updateWarehouse(warehouseVo));
    }

    /**
     * 查看仓库
     */
    @RequiresPermissions("warehouse:warmanage:modeling:query")
    @GetMapping("/view/{id}")
    public AjaxResult view(@PathVariable("id") Long id) {
        WarehouseDto dto = warehouseService.getView(id);
        return AjaxResult.success(dto);
    }

    /**
     * 删除仓库
     */
    @RequiresPermissions("warehouse:warmanage:modeling:remove")
    @Log(title = "删除仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable("id") Integer id) {
        return toAjax(warehouseService.deleteWarehouse(id));
    }


    /**
     * 新增子区域
     */
    @RequiresPermissions("warehouse:warmanage:modeling:addSubarea")
    @Log(title = "新增子区域", businessType = BusinessType.INSERT)
    @PostMapping("/addSubarea")
    public AjaxResult addSubarea(@Validated @RequestBody WarehouseVo warehouseVo) {
        return toAjax(warehouseService.addSubarea(warehouseVo));
    }

    /**
     * 根据库位编码获取仓库-库区-库位
     */
    @GetMapping("/getWarehouseCode")
    public AjaxResult getWarehouseCode(String warehouseCode) {
        return AjaxResult.success(warehouseService.getWarehouseCode(warehouseCode));
    }

    /**
     * 获取仓库-库区-库位列表
     */
    @GetMapping("/getCombinationWarehouse")
    public List<String> getCombinationWarehouse() {
        return warehouseService.getCombinationWarehouse();
    }

    /**
     * 获取仓库列表
     */
    @GetMapping("/getCkById")
    public AjaxResult getCkById() {
        return AjaxResult.success(warehouseService.getCkById());
    }


}
